package com.danskin.wechat.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.danskin.wechat.entity.CustFeedback;
import com.danskin.wechat.entity.CustInfo;
import com.danskin.wechat.service.CustFeedbackService;
import com.danskin.wechat.util.JsonUtils;
import com.danskin.wechat.util.Page;

@Controller
@RequestMapping("cust")
public class CustFeedbackController extends BaseController{

	@Autowired
	private CustFeedbackService custFeedbackService;
	
	@RequestMapping("/custFeedback")
	public String getList(CustInfo custInfo,Model model){
		return "custFeedback/feedback_list";
	}
	
	@RequestMapping(value = "/getCustFeedbackList", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Object getCustFeedbackList(Page page,HttpServletRequest request) throws Exception {
		Map map = getRequestParameter(this.getRequest());
		map.put("mpId", this.getLoginUser().getMpId());
		page.setMap(map);
		List<CustFeedback> list = custFeedbackService.listPageGetCustFeedback(page);
		return pagelistToJSONForBootStrapTable(list, page);
	}
	
	@RequestMapping(value = "/deleteCustFeedback", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String deleteCustFeedback(Integer id){
		Map<String,Object> map=new HashMap<String, Object>();
		
		int i = custFeedbackService.deleteCustFeedbackById(id);
		if(i>0){
			map.put("status", 0);
			map.put("msg", "成功");
		}else{
			map.put("status", 1);
			map.put("msg", "失败");
		}
		return JsonUtils.objectToJson(map);
	}
	@RequestMapping(value = "/updateReplayStatus", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String updateReplayStatus(Integer id){
		Map<String,Object> map=new HashMap<String, Object>();
		
		int i = custFeedbackService.updateCustFeedbackById(id);
		if(i>0){
			map.put("status", 0);
			map.put("msg", "成功");
		}else{
			map.put("status", 1);
			map.put("msg", "失败");
		}
		return JsonUtils.objectToJson(map);
	}
}
